package cn.xopencode.appletweb.controller.security.suggest;

import cn.xopencode.common.framework.vo.CommonResult;
import cn.xopencode.common.framework.vo.PageResult;
import cn.xopencode.score.api.rpc.ScoreRpc;
import cn.xopencode.securityservice.rpc.suggest.SuggestRpc;
import cn.xopencode.securityservice.rpc.suggest.dto.SuggestCreateReqDTO;
import cn.xopencode.securityservice.rpc.suggest.dto.SuggestPageReqDTO;
import cn.xopencode.securityservice.rpc.suggest.dto.SuggestRespDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Api(tags = "创新与合理化建议情况 API")
@RestController
@RequestMapping("/suggst")
@Validated
public class SecuritySuggstController {

    @DubboReference(version = "${dubbo.consumer.SuggestRpc.version}")
    private SuggestRpc suggestRpc;
    @DubboReference(version = "${dubbo.consumer.ScoreRpc.version}")
    private ScoreRpc scoreRpc;


    @ApiOperation(value = "根据ID获得创新与合理化建议情况")
    @GetMapping("/get/{suggestId}")
    public CommonResult<SuggestRespDTO> getSuggest(@PathVariable(value="suggestId",required=false)String suggestId) {
        return suggestRpc.getSuggest(suggestId);
    }

    /**
     * 分页获取创新与合理化建议情况
     * @param pageDTO
     * @return
     */
    @PostMapping("/page")
    @ApiOperation("分页获取创新与合理化建议情况")
    public CommonResult<PageResult<SuggestRespDTO>> pageSuggest(SuggestPageReqDTO pageDTO){
        return suggestRpc.pageSuggest(pageDTO);
    }

    /**
     *  新增创新与合理化建议情况
     * @param createDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增创新与合理化建议情况")
    public CommonResult<Integer> createSuggest(@Valid SuggestCreateReqDTO createDTO){
        Double score = scoreRpc.addSuggestScore(createDTO);
        createDTO.setScore(score);
        return suggestRpc.createSuggest(createDTO);
    }
}
